#@head() #@header()
<title>客户列表</title>
#@aside("user")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
<style>
	.box-body{padding:5px !important}
</style>
<div class="content-wrapper">
	<section class="content">
	<div class="nav-tabs-custom">
		#@usermenu("tzlb")
		
		<div class="tab-content">
		 <div class="tab-content">
		  <div class="tab-pane active" id="tab_1">
			<div class="box-body">
				<label style="float:left;margin-top:8px;margin-left:10px;">交易名称：</label>
                <input id="jyname" type="text" style="width:120px;float:left" class="form-control" placeholder="">
				<div style="float:left">
					<label style="float:left;margin-top:8px;margin-left:5px;">投资时间：</label>
					<input id="sjstart" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
					<label style="float:left;margin-top:8px;">—</label>
					<input id="sjend" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				</div>
				<div style="float:left">
					<label style="float:left;margin-top:8px;margin-left:5px;">还款时间：</label>
					<input id="hkstart"  style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
					<label style="float:left;margin-top:8px;">—</label>
					<input id="hkend" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">	
				
					<label style="float:left;margin-top:8px;margin-left:5px;">投资金额：</label>
					<input id="amountstart" style="width:120px;float:left"  type="text" class="form-control" placeholder="">
					<label style="float:left;margin-top:8px;">—</label>
					<input id="amountend" style="width:120px;float:left" type="text" class="form-control" placeholder=""> 
					<label style="float:left;margin-top:8px;margin-left:5px;">交易状态：</label>
					<select id="jyzt" style="width:120px;float:left" class="form-control">
						<option value="">全部</option>
						<option value="trading">投资中</option>
						<option value="repaying">还款中</option>
						<option value="finish">已还款</option>
					</select>
					<button id="seachuser" type="button" class="btn btn-info btn-flat">搜索</button>
				</div>
            </div>
			<div class="box-body">
				<table  id="example1" class="table table-striped">
					<thead>
						<tr>
							<th>交易流水号</th>
							<th>投资时间</th>
							<th>交易名称</th>
							<th>用户名</th>
							<th>真实姓名</th>
							<th>融资机构</th>
							<th>投资金额（元）</th>
							<th>所用优惠券</th>
							<th>还款时间</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="userlist">
						
					</tbody>
				</table>
				<div class="box-footer clearfix">
				  <ul class="pagination pagination-sm no-margin pull-right">
					<li id="userlist1"><a href="#">首页</a></li>
					<li id="userlist2"><a href="#">上一页</a></li>
					<li><a href="#">第<span id="userlist5"></span>页 共<span id="userlist6"></span>页</a></li>
					<li id="userlist3"><a href="#">下一页</a></li>
					<li id="userlist4"><a href="#">尾页</a></li>
				  </ul>
				</div>
			</div>
			</div>
		</div>
	</div>
	</section>
</div>
#@footer()
<script id="userlistall" type="text/x-jquery-tmpl">
	<tr>
		<td>${code}</td>
		<td>${create_time}</td>
		<td>${bidname}</td>
		<td>${mobile}</td>
		<td>${rzf}</td> 
		<td>${borrower}</td>
		<td>￥${amount}</td>
		<td>${youhui}</td>
		<td>${target_time}</td>
		<td>${status}</td>
		<td>
			<button onclick="window.open('#(path)/admin/page/enclosure-${isfor}?token=#(session.token??)&id=${id}&userId=${userid}&amount=${amount}')" type="button" class="btn btn-success">电子合同</button>
		</td>
		
	</tr>
</script>
<script>
var totalPage = 1;
var pageNumber = 1;
var jyname = "";
var sjstart = "";
var sjend = "";
var hkstart = "";
var hkend = "";
var jyzt = "";
var amountend = "";
var amountstart = "";
var userId = GetRequest().id; 
 $(document).ready(function(){
	pageNumber = 1;
	$("#userlist").empty();
	userlist(pageNumber,jyname,sjstart,sjend,hkstart,hkend,jyzt,amountend,amountstart);
	$("#userlist5").html(pageNumber);
});
$("#userlist1").click(function(){
	pageNumber = 1;
	$("#userlist").empty();
	userlist(pageNumber,jyname,sjstart,sjend,hkstart,hkend,jyzt,amountend,amountstart);
	$("#userlist5").html(pageNumber);
});
$("#userlist2").click(function(){
	if(pageNumber==1){
		alert("当前页是首页!");
	}else{
		$("#userlist").empty();
		pageNumber = pageNumber-1;
		userlist(pageNumber,jyname,sjstart,sjend,hkstart,hkend,jyzt,amountend,amountstart);
		$("#userlist5").html(pageNumber);
	}
});
$("#userlist3").click(function(){
	if(pageNumber==totalPage){
		alert("当前页是尾页!");
	}else{
		$("#userlist").empty();
		pageNumber = pageNumber +1;
		userlist(pageNumber,jyname,sjstart,sjend,hkstart,hkend,jyzt,amountend,amountstart);
		$("#userlist5").html(pageNumber);
	}
});
$("#userlist4").click(function(){
	$("#userlist").empty();
	pageNumber = totalPage; 
	userlist(pageNumber,jyname,sjstart,sjend,hkstart,hkend,jyzt,amountend,amountstart);
	$("#userlist5").html(pageNumber);
});
$("#seachuser").click(function(){
	$("#userlist").empty();
	pageNumber = 1;
	jyname = $("#jyname").val();
	sjstart = $("#sjstart").val();
	sjend = $("#sjend").val();
	hkstart = $("#hkstart").val();
	hkend = $("#hkend").val();
	jyzt = $("#jyzt").val();
	realname = $("#realname").val();
	amountend = $("#amountend").val();
	amountstart = $("#amountstart").val();
	userlist(pageNumber,jyname,sjstart,sjend,hkstart,hkend,jyzt,amountend,amountstart);
	$("#userlist5").html(pageNumber); 
});

function userlist(pageNumber,jyname,sjstart,sjend,hkstart,hkend,jyzt,amountend,amountstart){
	if(!$.isBlank(jyname)){
		jyname = '~'+jyname;
	}
	url = "#(path)/trade/list?token=#(session.token??)&page="+pageNumber+"&size=10&bidName="+jyname+"&createTimeStart="+sjstart+"&createTimeEnd="+sjend+"&targetTimeStart="+hkstart+"&targetTimeEnd="+hkend+"&status="+jyzt+"&amountEnd="+amountend+"&amountStart="+amountstart+"&userId="+userId;
	console.log(url)
	$.getJSON(url, function(userli) {
		console.log(userli);
		totalPage = userli.data.page.totalPage;
		$("#userlist6").html(totalPage);
		$.each(userli.data.page.list, function(i, item){ 
			var isfor = "printht";
			var userid = item.user_id;
			var youhui = "";
			if(!$.isBlank(item.tzhb)){
				youhui += "投资红包："+item.tzhb.amount+" 元 ";
			}
			if(!$.isBlank(item.tyj)){
				youhui += "体验金："+item.tyj.amount+" 元 ";
				isfor = "exprintht"; 
			}
			if(!$.isBlank(item.jxq)){
				youhui += "加息券："+item.jxq.amount +" % ";
			}
			if(item.status == "trading"){var status = "投资中"}
				else if(item.status == "repaying"){var status = "还款中 "}
				else if(item.status == "finish"){var status = "已还款 "}
			var userlist = {mobile:item.mobile,id:item.id,isfor:isfor,userid:userid,bid_id:item.bid_id,rzf:item.real_name,youhui:youhui,bidname:item.bid_name,status:status,target_time:item.target_time,code:item.code,create_time:item.create_time,mobile:item.mobile,amount:item.amount,borrower:item.borrower};
			$("#userlistall").tmpl(userlist).appendTo('#userlist');
		});
	});	
} 
 function GetRequest() {  
   var url = location.search; //获取url中"?"符后的字串  
   var theRequest = new Object();  
   if (url.indexOf("?") != -1) {  
	  var str = url.substr(1);  
	  strs = str.split("&");  
	  for(var i = 0; i < strs.length; i ++) {  
		 theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);  
	  }  
   }  
   return theRequest;  
}  

</script> 